﻿<ResourceDictionary x:Class="MainContentResources"
                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:common="clr-namespace:Brjnk.Common;assembly=Common"
                    xmlns:data="clr-namespace:Brjnk.GpxExplorer.Workspace"
                    xmlns:loc="clr-namespace:Brjnk.GpxExplorer.Localization"
                    xmlns:my="clr-namespace:Brjnk.GpxExplorer.WPF"
                    xmlns:vm="clr-namespace:Brjnk.GpxExplorer.ViewModel"
                    xmlns:workspace="clr-namespace:Brjnk.GpxExplorer.Workspace">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/GpxExplorer;component/Resources/BackgroundOperationsPanel.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <my:ListItemTemplateSelector x:Key="ListItemTemplateSelector" />

    <Grid x:Key="mainContent">
        <Grid.Resources />
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200" />
            <!--  GridSplitter  -->
            <ColumnDefinition Width="Auto" />
            <!--  MainContent  -->
            <ColumnDefinition />
            <!--  GridSplitter  -->
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="300" />
        </Grid.ColumnDefinitions>

        <ListView Name="list"
                  Grid.Column="0"
                  ItemsSource="{Binding Path='Data.AllObjects'}"
                  ItemTemplateSelector="{StaticResource ListItemTemplateSelector}"
                  SelectedItem="{Binding Source={workspace:GetWorkspace},
                                         Path=SelectedItem}">
            <ListView.ContextMenu>
                <ContextMenu>
                    <MenuItem Command="{Binding DataManager.RemoveObjectCommand}"
                              CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu},
                                                         Path=PlacementTarget.SelectedItems}"
                              Header="{loc:Loc remove}" />
                    <MenuItem Command="{Binding Editor.MakeVisibleCommand}"
                              CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu},
                                                         Path=PlacementTarget.SelectedItems}"
                              Header="{loc:Loc makeVisible}" />
                    <MenuItem Command="{Binding Editor.MakeInvisibleCommand}"
                              CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu},
                                                         Path=PlacementTarget.SelectedItems}"
                              Header="{loc:Loc makeInvisible}" />
                </ContextMenu>
            </ListView.ContextMenu>
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="IsSelected" Value="{Binding IsSelected}" />
                </Style>
            </ListView.ItemContainerStyle>
        </ListView>

        <Grid Grid.Column="2">
            <!--  Normální zobrazení Area2D s automatickou velikostí  -->
            <ContentPresenter Content="{Binding AreaManager.AutoSizeArea}" />
            <!--  Zobrazení Area2D s aktuálně vynucenou velikostí. Viewvbox provede případné zmenšení  -->
            <Border>
                <Viewbox StretchDirection="DownOnly">
                    <ContentPresenter Width="{Binding AreaManager.CustomSizeWidthDIP}"
                                      Height="{Binding AreaManager.CustomSizeHeightDIP}"
                                      Content="{Binding AreaManager.CustomSizeArea}" />
                </Viewbox>
            </Border>
            <Grid HorizontalAlignment="Right"
                  VerticalAlignment="Top"
                  Background="Beige"
                  Visibility="{Binding AreaManager.UsingCustomSize,
                                       Converter={StaticResource BooleanToVisibilityConverter}}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <TextBlock Grid.Row="0"
                           FontSize="15"
                           FontWeight="Bold"
                           Text="{loc:Loc Area2DDecreased}" />
                <StackPanel Grid.Row="1"
                            HorizontalAlignment="Right"
                            Orientation="Horizontal">
                    <TextBlock Text="{Binding AreaManager.CustomSizeWidth, Converter={StaticResource ShortLengthConverter}}" />
                    <TextBlock Text=" x " />
                    <TextBlock Text="{Binding AreaManager.CustomSizeHeight, Converter={StaticResource ShortLengthConverter}}" />
                </StackPanel>
            </Grid>
        </Grid>

        <Border Grid.Column="2"
                HorizontalAlignment="Right"
                VerticalAlignment="Bottom">
            <StaticResourceExtension ResourceKey="BackgroundOperationsPanel" />
        </Border>

        <Grid Grid.Column="4">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <ContentControl Name="detailsPlaceHolder" Grid.Row="1">
                <ContentControl Content="{Binding Source={x:Reference Name=list}, Path=SelectedItem}">
                    <ContentControl.ContentTemplateSelector>
                        <common:GenericTemplateSelector>
                            <common:TemplateDefinition ObjectType="{x:Type vm:WaypointVM}" Template="{StaticResource WaypointTemplate}" />
                            <common:TemplateDefinition ObjectType="{x:Type vm:RouteVM}" Template="{StaticResource RouteTemplate}" />
                            <common:TemplateDefinition ObjectType="{x:Type vm:TrackVM}" Template="{StaticResource TrackTemplate}" />
                        </common:GenericTemplateSelector>
                    </ContentControl.ContentTemplateSelector>
                </ContentControl>
            </ContentControl>

            <!--  Button nemůže být definován před ContentControl, aby fungovalo nastavení přes x:Reference  -->
            <Button HorizontalAlignment="Right"
                    Command="{StaticResource OpenInWindowCommand}"
                    CommandParameter="{x:Reference Name=detailsPlaceHolder}">
                <Button.Content>
                    <Image Height="16" Source="/Resources/Icons/Window.png" />
                </Button.Content>
                <Button.Style>
                    <Style TargetType="Button">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Source={x:Reference detailsPlaceHolder}, Path=Content}" Value="{x:Null}">
                                <Setter Property="Visibility" Value="Hidden" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Button.Style>
            </Button>
        </Grid>

        <GridSplitter Grid.Column="1"
                      Width="5"
                      HorizontalAlignment="Center"
                      VerticalAlignment="Stretch"
                      Style="{StaticResource GridSplitterStyle}" />
        <GridSplitter Grid.Column="3"
                      Width="5"
                      HorizontalAlignment="Center"
                      VerticalAlignment="Stretch"
                      Style="{StaticResource GridSplitterStyle}" />
    </Grid>
</ResourceDictionary>